#pragma once

#include "XBaseObjImpl.h"

#include "IXStringBundleMgr.h"
#include "IXFixedBuffer.h"

class CXStringBundleMgrImpl : public CXBaseObjImpl<IXStringBundleMgr>
{
    typedef CXBaseObjImpl<IXStringBundleMgr> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXStringBundleMgrImpl,
        superclass,
        gs_strGuidXSkin,
        IXStringBundleMgr,
        eIntf_Singleton);
public:
    CXStringBundleMgrImpl();
    virtual ~CXStringBundleMgrImpl();

public:
    // IXStringBundleMgr
    virtual HRESULT STDMETHODCALLTYPE   InitStringBundleMgr(IN LPCTSTR szSkinRootPath, IN LPCTSTR szLanguage);
    virtual HRESULT STDMETHODCALLTYPE   LoadString(OUT BSTR* pbstr, IN LPCTSTR szBundleName);
    virtual HRESULT STDMETHODCALLTYPE   EnumString(IN OUT DWORD pos, OUT BSTR* bstrId, OUT BSTR* bstrValue);
    // return S_OK if successfully, S_FALSE if restarting need, E_FAIL if failed(like no such language)
    virtual HRESULT STDMETHODCALLTYPE   put_Lang(LPCTSTR szLang);
    virtual HRESULT STDMETHODCALLTYPE   get_Lang(OUT BSTR* pbstrLang);

public:
    virtual void    STDMETHODCALLTYPE   OnFinalRelease();

protected:
    void        ReleaseData();
    HRESULT     ParseBundleFile(LPCTSTR szBundleName);
    BOOL        IsLangExists(LPCTSTR szLang, LPCTSTR szPath);

protected:
    typedef std::map<XString, StringMap> StringBundleMap;
    StringBundleMap     m_StringBundleMap;

    XString             m_strBundlePath;
    XString             m_strCurrentLang;
    XString             m_strSkinConfigPath;
};

